﻿using System.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QstkCore;
using QstkCore.Domain;
using QstkCore.Util;

namespace Tests
{
    [TestClass]
    public class FillNanTests
    {
        [TestMethod]
        public void FillForwardTest()
        {
            var sp = new StockPrices(new[] { float.NaN, 1, float.NaN, 2, float.NaN });
            sp.ReplaceNanFill(FillDirection.Forward);
            var expected = new[] { float.NaN, 1f, 1f, 2f, 2f };
            CollectionAssert.AreEqual(expected, sp.Prices);
        }

        [TestMethod]
        public void FillBackwardTest()
        {
            var sp = new StockPrices(new[] { float.NaN, 1, float.NaN, 2, float.NaN });
            sp.ReplaceNanFill(FillDirection.Backward);
            var expected = new[] { 1f, 1f, 2f, 2f, float.NaN };
            CollectionAssert.AreEqual(expected, sp.Prices);
        }

        [TestMethod]
        public void FillForwardThenBackwardTest()
        {
            var sp = new StockPrices(new[] { float.NaN, 1, float.NaN, 2, float.NaN });
            sp.ReplaceNanFill(FillDirection.Forward).ReplaceNanFill(FillDirection.Backward);
            var expected = new[] { 1f, 1f, 1f, 2f, 2f };
            CollectionAssert.AreEqual(expected, sp.Prices);
        }

        [TestMethod]
        public void FillBackwardThenForwardTest()
        {
            var sp = new StockPrices(new[] { float.NaN, 1, float.NaN, 2, float.NaN });
            sp.ReplaceNanFill(FillDirection.Backward).ReplaceNanFill(FillDirection.Forward);
            var expected = new[] { 1f, 1f, 2f, 2f, 2f };
            CollectionAssert.AreEqual(expected, sp.Prices);
        }
    }
}